package cn.bandeqing.payRecord.rpc.impl;

import cn.bandeqing.base.resp.Resp;
import cn.bandeqing.base.resp.Table;
import cn.bandeqing.payRecord.req.PayRecordTableReq;
import cn.bandeqing.payRecord.resp.PayRecordTable;
import cn.bandeqing.payRecord.rpc.IPayRecordRpc;
import cn.bandeqing.payRecord.service.IPayRecordService;
import cn.bandeqing.productType.resp.ProductTypeTable;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.hutool.core.text.StrUtil;

import static cn.bandeqing.payRecord.entity.table.PayRecordTableDef.PAY_RECORD;
import static cn.bandeqing.productType.entity.table.ProductTypeTableDef.PRODUCT_TYPE;

@DubboService
public class PayRecordRpcImpl implements IPayRecordRpc {

    @Resource
    private IPayRecordService payRecordService;

    @Override
    public Resp<Table<PayRecordTable>> table(PayRecordTableReq req) {
        QueryWrapper qw = QueryWrapper.create()
                .where(PAY_RECORD.ORDER_ID.eq(req.getOrderId()))
                .where(PAY_RECORD.PAY_SOURCE.eq(req.getPaySource()))
                .where(PAY_RECORD.PAY_TYPE.eq(req.getPayType()))
                .orderBy(PAY_RECORD.PAY_ID.desc());

        Page<PayRecordTable> page = payRecordService.pageAs(Page.of(req.getCurrent(), req.getPageSize()), qw, PayRecordTable.class);
        return Resp.success(Table.of(page.getRecords(), page.getTotalRow()));
    }

}
